﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Admin.CYT369.Com.WebBase
{
    public class PageViewModel
    {
        public static string ControlID(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string controlName, string prefix = null, string postfix = null, bool shortName = true)
        {
            var actionDescriptor = page.ViewContext.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
            string controllerName = actionDescriptor.ControllerTypeInfo.FullName.Replace(".", "_");
            if (shortName) { controllerName = actionDescriptor.ControllerName; }
            var name = string.Format("{0}_{1}_{2}_{3}_{4}", prefix, controllerName, actionDescriptor.ActionName, controlName, postfix);
            return name;
        }

        public static string PageTableID(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string prefix = null, string postfix = null, bool shortName = true)
        {
            var actionDescriptor = page.ViewContext.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
            string controllerName = actionDescriptor.ControllerTypeInfo.FullName.Replace(".", "_");
            if (shortName) { controllerName = actionDescriptor.ControllerName; }
            var name = string.Format("{0}_{1}_{2}_Grid_{3}", prefix, controllerName, actionDescriptor.ActionName, postfix);
            return name;
        }

        public static string PageTableToolbar(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string prefix = null, string postfix = null, bool shortName = true)
        {
            var actionDescriptor = page.ViewContext.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
            string controllerName = actionDescriptor.ControllerTypeInfo.FullName.Replace(".", "_");
            if (shortName) { controllerName = actionDescriptor.ControllerName; }

            var name = string.Format("{0}_{1}_{2}_ToolBar_{3}", prefix, controllerName, actionDescriptor.ActionName, postfix);
            return name;
        }

        public static string PageEditDialog(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string prefix = null, string postfix = null, bool shortName = true)
        {
            var actionDescriptor = page.ViewContext.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
            string controllerName = actionDescriptor.ControllerTypeInfo.FullName.Replace(".", "_");
            if (shortName) { controllerName = actionDescriptor.ControllerName; }

            var name = string.Format("{0}_{1}_{2}_Edit_Dlg_{3}", prefix, controllerName, actionDescriptor.ActionName, postfix);
            return name;
        }

        public static string PageViewDialog(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string prefix = null, string postfix = null, bool shortName = true)
        {
            var actionDescriptor = page.ViewContext.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
            string controllerName = actionDescriptor.ControllerTypeInfo.FullName.Replace(".", "_");
            if (shortName) { controllerName = actionDescriptor.ControllerName; }

            var name = string.Format("{0}_{1}_{2}_View_Dlg_{3}", prefix, controllerName, actionDescriptor.ActionName, postfix);
            return name;
        }

        public static string PageTableToolbarSearch(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string prefix = null, string postfix = null, bool shortName = true)
        {
            return PageFunctionNameArgs(page, "ToolBar_DoSearch", prefix, postfix, shortName: shortName);
        }

        public static string PageTableToolbarReset(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string prefix = null, string postfix = null, bool shortName = true)
        {
            return PageFunctionNameArgs(page, "ToolBar_DoReset", prefix, postfix, shortName: shortName);
        }

        public static string PageFunctionName(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string functionName, string prefix = null, string postfix = null, bool shortName = true)
        {
            var actionDescriptor = page.ViewContext.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
            string controllerName = actionDescriptor.ControllerTypeInfo.FullName.Replace(".", "_");
            if (shortName) { controllerName = actionDescriptor.ControllerName; }

            var name = string.Format("{0}_{1}_{2}_{3}_{4}", prefix, controllerName, actionDescriptor.ActionName, functionName, postfix);
            return name;
        }

        public static string PageFunctionNameArgs(Microsoft.AspNetCore.Mvc.Razor.IRazorPage page, string functionName, string prefix = null, string postfix = null, string args = null, bool shortName = true)
        {
            var actionDescriptor = page.ViewContext.ActionDescriptor as Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor;
            string controllerName = actionDescriptor.ControllerTypeInfo.FullName.Replace(".", "_");
            if (shortName) { controllerName = actionDescriptor.ControllerName; }

            var name = string.Format("{0}_{1}_{2}_{3}_{4}({5})", prefix, controllerName, actionDescriptor.ActionName, functionName, postfix, args);
            return name;
        }

    }

}
